import 'package:flutter/material.dart';

void main() {
  // 1.运行应用程序
  runApp(const MaterialApp(home: Main()));
}

class Main extends StatelessWidget {
  const Main({super.key});
  @override
  Widget build(BuildContext context) {
    // 2.构建应用程序界面
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          'gridVIew组件--1.基础用法',
          style: TextStyle(color: Colors.white),
        ),
        backgroundColor: Colors.black,
      ),
      // 中间内容
      body: Container(
        padding: const EdgeInsets.all(10),
        color: Colors.black12,
        child: GridView(
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 3, // 一行显示几个
            mainAxisSpacing: 10, // 主轴间距
            crossAxisSpacing: 10, // 交叉轴间距
            childAspectRatio: 100 / 50, // 宽高比
          ),
          children: [
            Container(
              color: Colors.red,
              alignment: Alignment.center,
              child: const Text('子项1'),
            ),
            Container(
              color: const Color.fromARGB(255, 70, 244, 54),
              alignment: Alignment.center,
              child: const Text('子项2'),
            ),
            Container(
              color: const Color.fromARGB(255, 244, 54, 206),
              alignment: Alignment.center,
              child: const Text('子项3'),
            ),
            Container(
              color: const Color.fromARGB(255, 244, 54, 171),
              alignment: Alignment.center,
              child: const Text('子项4'),
            ),
            Container(
              color: const Color.fromARGB(255, 86, 244, 54),
              alignment: Alignment.center,
              child: const Text('子项5'),
            ),
            Container(
              color: const Color.fromARGB(255, 54, 203, 244),
              alignment: Alignment.center,
              child: const Text('子项6'),
            ),
          ],
        ),
      ),
    );
  }
}
